/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;


import Entitys.Presentacion;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author MAURO
 */
public class PresentacionServices {
    EntityManagerFactory emf= Persistence.createEntityManagerFactory("DrugStoreProPU");
         EntityManager em=emf.createEntityManager();
         
         public void create (Presentacion p){
          em.getTransaction().begin();
          em.persist(p);
          em.getTransaction().commit();
          em.close();
         }
         
         public void delete (Integer   p){
          em.getTransaction().begin();
          Presentacion p1=em.find(Presentacion.class, p);
          if(p1!= null)
          em.remove(p1);
          em.getTransaction().commit();
          em.close();
         }
         
         public List<Presentacion> readAll(){
           Query q=em.createNamedQuery("Presentacion.findAll");
// por ver boolean n
//           if (n){
//            for (Iterator it = q.getResultList().iterator(); it.hasNext();) {
//                
//            }
//           }
           return q.getResultList();
         }
         
         
                 
    
}
